<template>
  <div id="storelist">
    <!-- 面包屑区域 -->
    <el-card class="box-card">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item><a href="/">一级菜单</a></el-breadcrumb-item>
        <el-breadcrumb-item>二级菜单</el-breadcrumb-item>
        <el-breadcrumb-item>三级菜单</el-breadcrumb-item>
      </el-breadcrumb>
    </el-card>
    <el-card class="box-card">
      <el-row>
        <span class="shopbox">商铺列表</span>
      </el-row>
      <br>
      <br>
      <el-form ref="form" label-width="80px" :model="form">
        <el-row :gutter="9">
          <el-col :span="8" class="shopcol">
            <el-form-item label="店铺名称:" prop="shopname">
              <el-input v-model="form.shopname" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8" class="shopcol">
            <el-form-item label="行业:" prop="industry">
              <el-select
                v-model="form.industry"
                placeholder="请选择"
                style="width: 100%;"
                @change="btn"
              >
                <el-option
                  v-for="(item, index) in options"
                  :key="index"
                  :label="item.label"
                  :value="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-button type="primary" @click="onSubmit">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-col>
          <el-col :span="2">
            <el-dropdown>
              <span class="el-dropdown-link" style="margin-left: 10px;">
                展开<i class="el-icon-arrow-down el-icon--right" />
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">黄金糕</el-dropdown-item>
                <el-dropdown-item command="b">狮子头</el-dropdown-item>
                <el-dropdown-item command="c">螺蛳粉</el-dropdown-item>
                <el-dropdown-item command="d" disabled>双皮奶</el-dropdown-item>
                <el-dropdown-item command="e" divided>蚵仔煎</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-button type="primary" @click="addok">+新增</el-button>
          </el-col>
        </el-row>
      </el-form>
      <!-- 表格 -->
      <template>
        <el-table :data="list" style="width: 100%;" class="table">
          <el-table-column type="selection" width="55" fixed />
          <el-table-column prop="shopname" label="店铺名称" width="120" fixed />
          <el-table-column prop="industry" label="行业" width="120" />
          <el-table-column prop="address" label="地址" width="120" />
          <el-table-column prop="mobile" label="电话" width="120" />
          <el-table-column prop="mobilename" label="推广人名称" width="120" />
          <el-table-column prop="interests" label="权益级别" width="120" />
          <el-table-column prop="interestsaging" label="权益时效" width="120" />
          <el-table-column prop="sales" label="销售额" width="120" />
          <el-table-column prop="state" label="状态" width="120" icon="el-icon-d-caret" />
          <el-table-column prop="nature" label="性质" width="120" icon="el-icon-d-caret" />
          <el-table-column prop="remark" label="备注" width="120" icon="el-icon-d-caret" />
          <el-table-column prop="date" label="操作" width="350" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" size="small" @click="handleClick(scope.row)">详情</el-button>
              <el-button type="text" size="small">查看商品</el-button>
              <el-button type="text" size="small">经营分析</el-button>
              <el-button type="text" size="small">启用/</el-button>
              <el-button type="text" size="small">停用</el-button>
              <el-button type="text" size="small" @click="opendell(row.id)">删除</el-button>
              <el-button type="text" size="small" @click="editstore(row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- 分页 -->
      <el-row :gutter="20">
        <el-col :span="14">
          <span>
            共{{ total }}条记录 第{{ this.page.page }}/{{ Math.ceil(total / this.page.size) }}页
          </span>
        </el-col>
        <el-col :span="5">
          <div class="grid-content bg-purple-light">
            <el-pagination
              background
              :current-page="page.page"
              :page-size="page.size"
              layout="prev,pager, next,sizes, jumper"
              :page-sizes="[5, 10, 15, 20]"
              :total="total"
              @size-change="handleSizeChange"
              @current-change="changePage"
            />
          </div>
        </el-col>
      </el-row>
    </el-card>
    <div>
      <add-storelist
        v-if="dialogVisible"
        :showadd.sync="dialogVisible"
        :dates="currentData"
        @changedialog="showding"
      />
    </div>

    <!-- ### -->
  </div>
</template>

<script>
import { shoreList, opendel, iqeshore, getindustry } from '@/api/shorelist';
import AddStorelist from './components/add-storelist';

export default {
  name: 'Storelist',
  components: {
    AddStorelist,
  },
  data() {
    return {
      dialogVisible: false, // 新增页显示与隐藏
      // 新增
      options: [],
      // 所属行业
      form: {
        shopname: '', // 店铺名称
        branchname: '', // 分店名称
        industry: '',
        idnumber: '', // 身份证号
        mailbox: '', // 注册邮箱
        scalselect: '', // 地图选点
        address: '', // 地址
        mobile: '', // 电话号码
        mobilename: '', // 推广人名称
        interests: '', // 权益级别
        interestsaging: '', // 权益时效
        sales: '', // 销售额
        state: '', // 状态
        nature: '', // 性质
        remark: '', // 备注
      },
      list: [],
      total: 0,
      page: {
        page: 1, // 当前页码
        size: 5, // 总数
      },
      currentData: {}, // 点击当前行存储当前行的数据
    };
  },
  created() {
    this.shoreList();
    this.getindustry();
  },
  methods: {
    // 渲染列表
    async shoreList() {
      const res = await shoreList(this.page);
      this.list = res.data;
      this.total = res.headers['x-total-count'] - 0;
    },

    // 获取行业
    async getindustry() {
      const { data } = await getindustry();
      data.forEach((item) => {
        this.options.push({ label: item.industry });
      });
    },

    btn() {
      this.options = [];
      console.log(this.options);
      this.getindustry();
    },

    // 查询
    async onSubmit() {
      if (this.form.shopname) {
        const { data } = await iqeshore({ shopname: this.form.shopname });
        this.list = data;
      } else if (this.form.industry) {
        const { data } = await iqeshore({ industry: this.form.industry });
        this.list = data;
      } else {
        this.shoreList();
      }
    },

    // 重置表单
    reset() {
      this.form = {
        shopname: '', // 店铺名称
        industry: '', // 所属行业
      };
    },

    // 删除
    async opendell(id) {
      try {
        await this.$confirm('确定要删除员工吗？');
        await opendel(id);
        await this.shoreList();
        this.$message.success('删除员工成功');
      } catch (error) {
        console.log(error);
      }
    },

    // 新增
    addok() {
      console.log('1122');
      this.currentData = {};
      this.dialogVisible = true;
    },

    // 编辑
    editstore(data) {
      this.dialogVisible = true;
      this.currentData = data;
      this.data = data;
    },

    // 定义关闭弹窗
    showding(valus) {
      this.showDialog = valus;
    },

    // 分页跳转
    changePage(newPage) {
      this.page.page = newPage;
      this.shoreList();
    },
    handleSizeChange(val) {
      this.page.size = val;
      this.shoreList();
    },
  },
};
</script>

<style lang="less">
body {
  background-color: #f0f2f5;
  .box-card {
    margin: 20px;
    color: #8d8d8d;
  }
  .shopbox {
    color: #000;
    font-size: 20px;
    font-weight: 400;
  }
  .shopcol {
    margin-left: 40px;
  }
  .btnq {
    margin-left: 20px;
    width: 80px;
  }
  .btn {
    width: 80px;
  }
  .el-col el-col-4 {
    justify-content: center;
    align-items: center;
    display: flex;
  }
  .touxian {
    height: 100px;
    width: 100px;
    background-color: #000;
  }
  .file {
    height: 100px;
    width: 100px;
    border: 1pxsolid;
  }
  .el-dropdown {
    margin-top: 10px;
  }
}
</style>
